package ai.people.netmon.framework.domain.gang.construction.bo;

import ai.people.netmon.framework.domain.gang.construction.entity.RelationRule;
import com.alibaba.fastjson.JSONArray;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 关系库-类型
 * </p>
 *
 * @author zhenglin
 * @since 2022-07-19
 */
@Data
public class RelationLibConfigBo implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    private Long id;

    /**
     * 扩线关系点value
     */
    private String expListValue;
    /**
     * 扩线关系点name
     */
    private String expListName;
    /**
     * 类型value
     */
    private String expTypeValue;
    /**
     * 类型name
     */
    private String expTypeName;

    /**
     * 规则ID
     */
    private Long relationRuleId;

    /**
     * 规则名称
     */
    private String relationRuleName;

    /**
     * 配置的规则
     */
    private String rule;

    /**
     * 是否禁用 1是 0否
     */
    private Integer lockFlag;


    public List<RelationRule.Rule> buildRule() {
        if (StringUtils.isNotBlank(rule)) {
            return JSONArray.parseArray(rule, RelationRule.Rule.class);
        }
        return Collections.emptyList();
    }
}
